//
//  LGStatusListviewModel.swift
//  LGWeibo
//
//  Created by 李更 on 8/14/16.
//  Copyright © 2016 itcast. All rights reserved.
//

import UIKit

class LGStatusListviewModel: NSObject {
    
    //保存微博数据的数组
    lazy var dataArray : [LGStatusViewModel] = [LGStatusViewModel]()
    
    

}
extension LGStatusListviewModel{
    
    func loadData(finish :(isSuccess : Bool)->()) {
        HMNetworkTools.sharedTools.homeLoadData({ (response) in
            print("请求数据成功:\(response)")
            guard let res = response?["statuses"] as? [[String :AnyObject]] else{
                finish(isSuccess: false)
                return
            }
            var tempArray : [LGStatusViewModel] = [LGStatusViewModel]()
            
            for dic in res{
                let statuses = LGStatusModel(dict: dic)
                let statusViewModel = LGStatusViewModel(statusModel: statuses)
                tempArray.append(statusViewModel)
                
            }
            
            self.dataArray = tempArray

            print(self.dataArray.count)
            finish(isSuccess: true)
        }) { (error) in
            print("请求数据失败:\(error)")
            finish(isSuccess: false)
        }
    }
}